package com.mingqijia.gassafety.console.controller;

import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.webserver.request.QueryListShowRequest;
import com.mingqijia.gassafety.webserver.request.UpdateListShowRequest;
import com.mingqijia.gassafety.webserver.service.FieldListShowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author zhangfei
 * @version 1.0.0
 * @ClassName FieldListShowController.java
 * @Description 系统列表字段自定义
 * @createTime 2023年09月22日
 */
@RestController
@Api(tags = "系统列表字段自定义")
@RequestMapping("/business/v1/field")
@Slf4j
public class FieldListShowController {

    @Autowired
    private FieldListShowService fieldListShowService;

    private static final String DEFAULT_SHOW="system";

    /**
     * 更新企业列表字段配置
     *
     * @param request
     * @return
     */
    @PostMapping("updateListShow")
    @ApiOperation(value = "更新企业列表字段配置")
    public CommonResponse<Object> updateListShow(@RequestBody @Valid UpdateListShowRequest request) {
        fieldListShowService.addListShow(request);
        return CommonResponse.success(null);
    }


    /**
     * 查询企业列表字段配置
     *@param request 列表编码
     * @return
     */
    @PostMapping("queryListShow")
    @ApiOperation(value = "查询企业列表字段配置")
    public CommonResponse<Object> queryListShow(@RequestBody @Valid QueryListShowRequest request) {
        return CommonResponse.success(fieldListShowService.queryListShow(request.getListCode()
                ,request.getDefaultShow()==0?DEFAULT_SHOW:null));
    }

    /**
     * 查询企业列表字段页面展示
     *@param request 列表编码
     * @return
     */
    @PostMapping("listShowMapping")
    @ApiOperation(value = "查询企业列表字段页面展示")
    public CommonResponse<Object> listShowMapping(@RequestBody @Valid QueryListShowRequest request) {
        return CommonResponse.success(fieldListShowService.queryListShowByShowStatus(request.getListCode()
                ,request.getDefaultShow()==0?DEFAULT_SHOW:null));
    }

    /**
     * 更新企业列表字段配置
     *
     * @param request
     * @return
     */
    @PostMapping("updateConfig")
    @ApiOperation(value = "更新企业列表字段配置")
    public CommonResponse<Object> updateConfig(@RequestBody @Valid UpdateListShowRequest request) {
        fieldListShowService.updateConfig(request);
        return CommonResponse.success(null);
    }
}